<?php

if($_POST['xmlhttp']){
	include_once('config.php');
	include_once(mnminclude.'KMessaging.php');
	include_once(mnminclude.'user.php');
	include_once(mnminclude.'group.php');

	$message =  new KMessaging();
	$message->tblName = table_messages;
	$title = '';
	$body = '';
	$user = new User();
	$user->id = $_POST['sender'];
	$user->read();
	$group = new Group();
	$group->id = $_POST['group'];
	$group->read();
	$title = $title . $user->names . "邀请您加入" . $group->name . "小组";
	$body = $body . '<a target="_blank" href="user.php?uid=' . $user->id . '">' . $user->names . '</a>邀请您加入' . '<a target="_blank" href="group.php?id=' . $group->id . '">' . $group->name . '</a>小组' . '<br />'; //should use ' outside and " inside
	$body = $body . '您可<a href="javascript:" onclick="group_accept_invite('. $_POST['receiver'] . ',' . $_POST['group'] .')">接受</a>或<a href="javascript:" onclick="group_deny_invite('. $_POST['receiver'] . ',' . $_POST['group'] .')">拒绝</a>此邀请.';
	$sendmsg = $message->SendMessege($title,$body,$_POST['sender'],$_POST['receiver'],$_POST['senderlevel']);
	//echo $sendmsg . " end sql";
	//die();
	if ($sendmsg == 0) {
		$group->add_user($_POST['receiver'],'normal','invited');
	}
	switch ($sendmsg) {
		case 0:
			echo "success";
			die();
			break;
		case 2:
			echo "nobody";
			die();
			break;
		case 1:
			echo "notitle";
			die();
			break;
		case 6:
			echo "database_error";
			die();
			break;
		default:
			echo "fail";
			die();
			break;
	}
}
?>